<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>客户还款列表</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span class="separator"></span>
                <span>发货人:</span>
                <div id="keyCustomerId" name="keyCustomerId" class="mini-autocomplete" style="width:250px;"  popupWidth="1000" textField="name" valueField="id"
                     url="${base}/pages/customer_manage/queryDeliveryCustomerByKey"  required="false" requiredErrorText="发货人不能为空"
                     searchField="key"
                     emptyText="发货人名称">
                    <div property="columns">
                        <div header="发货人名称" field="name"></div>
                        <div header="发货人简称" field="shortName"></div>
                        <div header="发货人电话" field="phone"></div>
                        <div header="发货人地址" field="address"></div>
                    </div>
                </div>

                <span class="separator"></span>
                <span>还款方式:</span>
                <input id="keyRepaymentWayId" name="keyRepaymentWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                       required="true" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择还款方式"/>

                <span class="separator"></span>
                <span>审核状态:</span>
                <input id="keyAuditStatusId" name="keyAuditStatusId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                       required="true" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择审核状态"/>


                <span>登记人:</span>
                <input id="keRegistUserId" name="keRegistUserId"  class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                       required="true" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择登记人" />

                <span class="separator"></span>
                <span>还款日期：</span>
                <input id="keyRegistStartDate" name="keyRegistStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>
                --
                <input id="keyRegistEndDate" name="keyRegistEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>

                <div style="margin-top: 5px"></div>

                <% if(so.hasPermission("cwRepaymentList:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchRepayment()">查询</a>
                <% } %>

                <% if(so.hasPermission("cwRepaymentList:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("cwRepaymentList:approved")){%>
                    <a class="mini-button" iconCls="icon-edit" onclick="audit(312)">审核通过</a>
                <% } %>


                <% if(so.hasPermission("cwRepaymentList:back")){%>
                    <a class="mini-button" iconCls="icon-edit" onclick="audit(311)">审核退回</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("cwRepaymentList:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="客户还款信息表"/>
                <% } %>


            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/repayment/queryRepaymentList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="registDate"
                 sortOrder="desc"
                 ondrawsummarycell="summaryRight">

                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="customerId" width="180" headerAlign="center" align="left" allowSort="true" data-options='{cacheName:"customer"}' renderer="commonRender">发货人</div>
                    <div field="phone" width="140" headerAlign="center" align="left" allowSort="false" renderer="commonDesensitization">电话</div>
                    <div field="address" width="200" headerAlign="center" align="left" allowSort="false">地址</div>
                    <div field="repaymentWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">还款方式</div>
                    <div field="amount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">还款金额</div>
                    <div field="availableAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">可用还款金额</div>
                    <div field="registUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">还款登记人</div>
                    <div field="registDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">登记日期</div>
                    <div field="voucherFileId" width="140" headerAlign="center" align="center" allowSort="false" renderer="viewImgRender">查看凭证</div>

                    <div field="auditStatusId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">审核状态</div>
                    <div field="auditUserId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">审核人</div>
                    <div field="auditDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">审核时间</div>
                    <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>

                </div>
            </div>

        </div>

        <script type="text/javascript">
            mini.parse();

            let keyCustomerId = mini.get("keyCustomerId");
            let keyRepaymentWayId = mini.get("keyRepaymentWayId");
            let keyAuditStatusId = mini.get("keyAuditStatusId");
            let keRegistUserId = mini.get("keRegistUserId");
            let keyRegistStartDate = mini.get("keyRegistStartDate");
            let keyRegistEndDate = mini.get("keyRegistEndDate");

            // 主 grid
            let grid = mini.get("datagrid1");


            // 审核状态
            let auditStatus = {unaudited:311, audited:312};

            $(function () {

                let keyRepaymentWayIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_REPAYMENT_WAY");
                keyRepaymentWayId.load(keyRepaymentWayIdJsonData);

                let keyAuditStatusIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_AUDIT_STATUS");
                keyAuditStatusId.load(keyAuditStatusIdJsonData);

                let keRegistUserIdJsonData = getCacheList("sysUser");
                keRegistUserId.load(keRegistUserIdJsonData);

                // 加载列表数据
                grid.load();
            });

            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            /**
             * 根据查询条件查询
             */
            function searchRepayment(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }

            /**
             *
             */
            function audit(statusId){
                let selectItems = grid.getSelecteds();
                if(selectItems.length == 0){
                    showAlert("没有选择需要审核的还款记录!",null);
                    return;
                }

                // 开始遍历
                let aduitIds = "";
                let idArray=[];

                let msg = statusId == auditStatus.audited ? "包含已审核的行" : "包含未审核的行";
                msg += "，请重新选择!";

                for(let obj of selectItems){
                    if(obj.auditStatusId != statusId){
                        idArray.push({id:obj.id});
                    }
                    else{
                        aduitIds += obj.id + " ";
                    }
                }

                if(aduitIds.length>0){
                    showAlert("选择的行中" + msg,null);
                    return;
                }

                // 到此校验全部成功，可以入库了
                let clearNatvieBillServiceChargeUrl = "${base}/pages/finance_manage/repayment/updateAuditStatus";
                let ret = public_getServerData(clearNatvieBillServiceChargeUrl, {idList:idArray,auditStatusId:statusId});
                showAlert(ret.message,function (){
                    grid.reload();
                });

            }


            /**
             * 生成查看图片按钮
             */
            function viewImgRender(e){
                let viewHtml = "<a class='mini-button' style='width: 40px' onclick='viewImg(\"" + e.value + "\")'>查看</a>";
                return viewHtml;
            }


            /**
             * 弹出窗口，加载图片返回数据源进行显示
             */
            function viewImg(imageId){
                public_showImageOfLarge("${base!}",imageId,true,"凭证图片",800,800)
            }

            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;";
            }

        </script>
    </body>
</html>